import { GetTime } from '@/util/date.js';
import { randomString } from '@/util/common.js';
import { wxAppId } from './config.js';

export default {
	payment: function(res){
		return new Promise((resolve, reject) => {
			uni.requestPayment({
				provider: 'wxpay',
				appId: res.appId,
				timeStamp: String(res.timeStamp),
				nonceStr: res.nonceStr,
				package: `prepay_id=${res.prepay_id}`,
				signType: 'MD5',
				paySign: res.paySign,
				success: function (res) {
					// this.subscribeMessage('pay');
					resolve(res);
				},
				fail: function (err) {
					console.log(err);
					reject(err);
				}
			});
		});		
	},
	subscribeMessage: function(type, callback, extData){
		const tmplIds = {
			'pay':[
				'nOrpPHyR0EwTTtmeZnADiCqONAlYvNJLraSCVH1J2CE',
				'piMtzNN_6kKX9ppjC21GTOqwCf06TFXL9k1B8C_YVyM',
				'II9jGLCF3OKj612U9x3EyhbHn7ik5utHLfmEEDyvyDI'
			],
			'user': [
				'IdQ5n4C9fTVJXjlJZDlxmOOeRv7o-6hQaqH-9dFag88',
				'cwtMpHPIoYxHZIyvO2hABqs37FJ_svUrH-F0_A4UilU',
			]
		}
		wx.requestSubscribeMessage({
		  tmplIds: tmplIds[type],
		  success (res) {
			  console.log(res)
		  },
		  fail(err) {
		  	console.log(err)
		  },
		  complete() {
		  	if(typeof callback === 'function') callback(extData);
		  }
		});
	}
}